﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
   
    internal class Program
    {
        public class CreditCard
        {//信用卡
            float quota = 10000;//信用卡总额度设定为10000
            float backmoney;//还款金额
            int today;//今日日期
            int backday=30;//S设定还款日为30号
            DibitCard card;//储蓄卡
            public  CreditCard(float backmoney,int today,DibitCard card)
            {       
                    this.backmoney = backmoney;
                    this.today = today;
                    this.card = card;   
            }
            public void Check() {
                CheckDay(card,today);
            }
           public void CheckDay(DibitCard card,int nowday)
            {
                
                if (nowday == backday)
                {
                    Console.Write("{0}号为还款日期，", nowday);
                    if (backmoney < card.show())//余额大于还款金额
                    {
                        float leftmoney = card.show() - backmoney;//余额
                        card.setback(leftmoney);//设置还款后储蓄卡的余额
                        Console.Write("你今日需还款{0}元\n扣除成功，储蓄卡余额为{1}元\n", backmoney, leftmoney);
                    }
                    else if(backmoney > quota)
                    {//检查是否超过设定的总额度
                        Console.WriteLine("设定还款金额为{0}超过信用卡总额度10000元，操作失败\n", backmoney);
                    }

                    else
                    {
                        Console.WriteLine("还款失败,余额储蓄卡余额不足\n");
                    }

                }
                else
                {
                    Console.WriteLine("\n今日无需还款\n");


                }
                         
             
                }
        }
        public class DibitCard
        {//储蓄卡
            float savemoney;
            float leftmoney;
            public DibitCard(float savemoney)
            {
                this.savemoney = savemoney;
            }
            public float show()//显示存储金额
            {
                return this.savemoney;
            }
            public void setback(float leftmoney)//还款后的剩余金额
            {
                this.leftmoney = leftmoney; 
            }
        }
        class Delegate
        {
            // 定义委托
            public delegate void MeDelegate();
            // 定义事件
            public event MeDelegate NotifyEveryOne;
            public void Notify()
            {
                // 如果事件不为 null
                if (NotifyEveryOne != null)
                {
                    Console.WriteLine("触发事件：");
                    // 触发事件
                    NotifyEveryOne();
                }
            }
        }
        static void Main(string[] args)
        {
            Delegate objDelegate = new Delegate();//委托的对象

            DibitCard d1 = new DibitCard(10000);//设定d1金额为10000；

            CreditCard c1 = new CreditCard(100, 30,d1);//还款日
            CreditCard c2 = new CreditCard(100, 20,d1);//非还款日
            CreditCard c3 = new CreditCard(100000, 30, d1);//设定还款金额超出总额度
            objDelegate.NotifyEveryOne +=new Delegate.MeDelegate(c1.Check);
            objDelegate.NotifyEveryOne += new Delegate.MeDelegate(c2.Check);
            objDelegate.NotifyEveryOne += new Delegate.MeDelegate(c3.Check);
            objDelegate.Notify();


        }
    }

}
